﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Betfairer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

       
        }

        //private Dictionary<String, Int32> CalculateMarketsFrequencies()
        //{
        //    List<SportEvent> sportEvents = global.GetSportEvents();
        //    Dictionary<String, Int32> result = new Dictionary<string, int>();

        //    foreach (SportEvent sportEvent in sportEvents)
        //    {

        //    }
        //}

        //private void PlaceBet(int marketId)
        //{
        //    Table table = new Table(Global.Instance.GetOdds(marketId));
        //}

 

        //private Dictionary<String, Int32> Calculate

        private static bool IsFootball(SportEvent input)
        {
            return input.Id == 1;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Connect();
        }

        private void Connect()
        {
            textBox3.Text = "Connection...";
            //textBox3.Text = global.Login(textBox1.Text, textBox2.Text);
            textBox3.Text += Environment.NewLine + Global.Instance.Login(textBox1.Text, textBox2.Text);
            Global.Instance.GetProfile();
            textBox3.Text += Environment.NewLine + "Denezhki: " + Global.Instance.GetAccountFunds();
            foreach (SportEvent item in Global.Instance.GetSportEvents())
            {
                //listBox1.Items.Add(item);
                comboBox1.Items.Add(item);
                //comboBox1.Items.
            }


            //foreach (string str in global.GetSoccerEvents())
            //{
            //    textBox3.Text += str + Environment.NewLine;
            //}
        }

        public void PopulateTreeView(TreeView tv, List<Market> markets)
        {
            string[] ids;
            string[] names;
            TreeNodeCollection nodes;
            tv.Nodes.Clear();

            for (int i = 0; i < markets.Count; ++i)
            {
                Market market = markets[i];

                ids = market.EventHeirachy.Split('/');
                names = market.MenuPath.Split('\\');
                nodes = tv.Nodes;

                for (int j = 0; j < ids.Length; ++j)
                {
                    if (!nodes.ContainsKey(ids[j]))
                    {
                        TreeNode node = new TreeNode(j < names.Length ? names[j] : market.MarketName);
                        //node.Text = j < names.Length ? names[j] : market.MarketName;
                        node.Name = ids[j];
                        nodes.Add(node);
                    }
                    nodes = nodes[ids[j]].Nodes;
                }
            }
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            //if (e.Node.Nodes.Count == 0)
            //{
            //    Global.Instance.GetOdds(Convert.ToInt32(e.Node.Name));
            //    //global.GetOdds("26867050");
            //}
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //int id = ((SportEvent)comboBox1.SelectedItem).Id;
            //PopulateTreeView(treeView1, Global.Instance.GetMarkets(id));
        }
    }
}
